import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import { resolve } from 'path';
import Components from 'unplugin-vue-components/vite';
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
import AutoImport from 'unplugin-auto-import/vite'; //! 可以自动导入vue和vue-router,vuex的api

// https://vitejs.dev/config/
export default defineConfig({
	plugins: [
		vue(),
		AutoImport({
			imports: ['vue', 'vue-router'],
			resolvers: [
				ElementPlusResolver(), // 自动导入图标组件
			],
		}),
		Components({
			resolvers: [ElementPlusResolver()],
			dirs: ['src/components'],
		}),
	],

	base: './',
	resolve: {
		//todo 配置别名
		alias: {
			'/@': resolve(__dirname, './src/components'),
		},
	},
	server: {
		proxy: {
			//代理（解决跨域问题）
			'/api': {
				target: 'https://fc-mp-91187d2c-1225-4c77-b616-a32b09715ff4.next.bspapp.com',
				// target: 'https://admin.coretecnology.com',
				ws: true,
				changeOrigin: true,
				rewrite: (path) => path.replace(/^\/api/, ''),
			},
		},
	},
	build: {
		sourcemap: false,
		// minify: 'terser',
		terserOptions: {
			compress: {
				drop_console: true,
				drop_debugger: true,
			},
		},
		target: 'esnext',
		minify: false,
		cssCodeSplit: false,
		rollupOptions: {
			output: {
				minifyInternalExports: false,
			},
		},
	},
});
